<?php

namespace App\Admin\Controllers;

use App\Models\Cart;
use App\Models\Customer;
use App\Models\Product;
use Encore\Admin\Controllers\AdminController as Controller;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CartController extends Controller
{
    protected $title = "购物车管理";

    protected function grid()
    {
        $grid = new Grid(new Cart);

//        $grid->filter(function ($filter){
//            $filter->equal('customer_id','顾客手机号')->select(Customer::query()->pluck('mobile','id'));
//            $filter->equal('product_id','商品名')->select(Product::query()->pluck('name','id'));
//        });
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->disableRowSelector();

        $grid->id('ID');
        $grid->customer_id('顾客ID');
        $grid->product_id('商品ID');
        $grid->sku_id('SKU ID');
        $grid->number('数量');
        $grid->created_at(__('Created at'));
        $grid->updated_at(__('Updated at'));

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Cart::findOrFail($id));

        $show->id('ID');
        $show->customer_id('顾客ID');
        $show->product_id('商品ID');
        $show->sku_id('Sku ID');
        $show->number('数量');
        $show->created_at(__('Created at'));
        $show->updated_at(__('Updated at'));

        return $show;
    }

    protected function form()
    {
        $form = new Form(new Cart);

        $form->number('customer_id', '顾客ID');
        $form->number('product_id', '商品ID');
        $form->number('sku_id', 'Sku ID');
        $form->number('number', '数量');

        return $form;
    }
}
